//
//  UMVerifyHandler.m
//  umeng_vertify
//
//  Created by Yunxi on 2021/8/26.
//

#import "UMVerifyHandler.h"
#import <UMCommon/UMConfigure.h>
#import <UIKit/UIKit.h>
#import "ProgressHUD.h"


@implementation UMVerifyHandler

- (void)initUMCommon{
//    NSLog(@"一键登录---初始化友盟sdk");
    [UMConfigure initWithAppkey:@"5fd0448dfb95730a9f82dd0e" channel:@"yyt"];
}

- (void)setVerifySDKInfoWithSecret:(NSString *)secret complete:(void (^_Nullable)(NSDictionary * _Nonnull resultDic))complete{
    NSLog(@"一键登录---设置验证sdk密钥");
    
    [UMCommonHandler setVerifySDKInfo:secret complete:^(NSDictionary * _Nonnull resultDic) {
        NSLog(@"setVerifySDKInfo----%@", resultDic);
        complete(resultDic);

    }];
    
}

- (void)checkEnvAvailableWithType:(UMPNSAuthType)type complete:(void (^_Nullable)(NSDictionary * _Nonnull resultDic))complete{
    NSLog(@"一键登录---验证一键登录可用性");

    [UMCommonHandler checkEnvAvailableWithAuthType:type complete:^(NSDictionary * _Nullable resultDic) {
        NSLog(@"checkEnvAvailableWithAuthType----%@", resultDic);
//        resultDic[@"resultCode"] = @"600000";
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:resultDic];

        NSString*code =[resultDic objectForKey:@"resultCode"];

        if([@"600000" isEqualToString:code]){
            dic[@"resultCode"] = @"600024";
        }

        complete(dic);

    }];
}

- (void)getLoginTokenWithTimeoutWithTimeOut:(NSTimeInterval)timeOut complete:(void (^_Nullable)(NSDictionary * _Nonnull resultDic))complete{
    NSLog(@"一键登录---调起一键登录页面");
    NSLog(@"看看model还有值吗？：%@", customodel.changeBtnTitle);


    NSLog(@"getLoginTokenWithTimeout");
    
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
        
    [UMCommonHandler accelerateVerifyWithTimeout:timeOut complete:^(NSDictionary * _Nonnull resultDic) {
            NSLog(@"accelerateVerifyWithTimeout----%@", resultDic);
        }];
    
    [UMCommonHandler getLoginTokenWithTimeout:timeOut controller:window.rootViewController model:customodel complete:^(NSDictionary * _Nonnull resultDic) {
        NSLog(@"getLoginTokenWithTimeout----%@", resultDic);
        complete(resultDic);

    }];
}

+ (void)cancelLoginVC{
    [ProgressHUD dismiss];
    [UMCommonHandler cancelLoginVCAnimated:YES complete:^{}];
}

+ (void)modelConfigWithModel:(UMCustomModel *)customModel{
    
    NSLog(@"调用设置model方法:%@",customModel);
    customodel = customModel;
}

+ (void)changeBtnShowWithHidden:(BOOL)hidden title:(NSString *)title {
    NSLog(@"修改之前:%@",customodel.changeBtnTitle);
//yes--""
    //no--"随便逛逛"
    customodel.changeBtnIsHidden = hidden;
    customodel.changeBtnTitle = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:0.6],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}];
    NSLog(@"修改成功了吗:%@",customodel.changeBtnTitle);

}

@end
